function reverseStr(str) {
  let result = '';
  let start = 0;
  for(let i = 0; i<str.length; i++) {
    let current = str.charAt(i);
    if(current === ' ' || current === ',' || current === '.' || current === '?') {
      let word = str.substring(start, i).split('');
      result = result + word.reverse().join('') + current;
      start = i+1;
    } else if(i === str.length - 1) {
      let word = str.substring(start, i+1).split('');
      result = result + word.reverse().join('');
    }
  }
  console.log(result)
}
reverseStr('olleH,yM eman si boB.')